<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <h1 id="clock">
        <span></span>
    </h1>

    <script>
        let h1 = document.getElementById('clock');

        //每隔一秒获取一次时间
        setInterval(function () {
            let date = new Date();
            let t = date.toLocaleTimeString();
            let textNode=document.createTextNode(t);
            let span=document.createElement('span');
            span.appendChild(textNode);
            h1.replaceChild(span,h1.firstElementChild)

        }, 1000)





    </script>

</body>

</html>